$OpenBSD: patch-stk500v2_c,v 1.5 2013/05/05 16:48:08 edd Exp $
--- stk500v2.c.orig	Fri Aug 26 21:22:10 2011
+++ stk500v2.c	Sat May  4 10:30:28 2013
@@ -319,6 +319,7 @@ static void stk500v2_jtagmkII_setup(PROGRAMMER * pgm)
 void stk500v2_teardown(PROGRAMMER * pgm)
 {
   free(pgm->cookie);
+  pgm->cookie = NULL;
 }
 
 static void stk500v2_jtagmkII_teardown(PROGRAMMER * pgm)
@@ -330,6 +331,7 @@ static void stk500v2_jtagmkII_teardown(PROGRAMMER * pg
   jtagmkII_teardown(pgm);
 
   free(mycookie);
+  pgm->cookie = NULL;
 }
 
 
@@ -1158,12 +1160,14 @@ static int stk500hv_initialize(PROGRAMMER * pgm, AVRPA
   if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) {
     fprintf(stderr, "%s: stk500pp_initialize(): Out of memory\n",
 	    progname);
+    PDATA(pgm)->eeprom_pagecache = NULL;
     return -1;
   }
   if ((PDATA(pgm)->eeprom_pagecache = malloc(PDATA(pgm)->eeprom_pagesize)) == NULL) {
     fprintf(stderr, "%s: stk500pp_initialize(): Out of memory\n",
 	    progname);
     free(PDATA(pgm)->flash_pagecache);
+    PDATA(pgm)->flash_pagecache = NULL;
     return -1;
   }
   PDATA(pgm)->flash_pageaddr = PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
